package com.gilight.base.controller;

import com.gilight.base.dto.CodeGeneratorDto;
import com.gilight.base.service.CodeGeneratorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/web/codeGenerator")
public class CodeGeneratorController {
    @Autowired
    private CodeGeneratorService codeGeneratorService;

    @RequestMapping(value = "/generate", method = {RequestMethod.GET})
    public ResponseEntity<byte[]> generate(CodeGeneratorDto codeGeneratorDto) {
        String path = codeGeneratorService.generate(codeGeneratorDto);
        return codeGeneratorService.zipAndDownload(path);
    }
}
